1 前処理

2 グラフ描画

  • max_draqdown(リーマンショックの経験から50%とする)
  • under2σ(日次リターン過去1年分の)
  • over2σ(日次リターン過去1年分の)

2.1 2510

tarTicker <- c("2510")
data1 <- daily1 %>%
  filter(ticker == tarTicker) %>%
  tail(., 300) %>%
  mutate(return = close / dplyr::lag(close) - 1)
max_drawdown <- tail(data1$close, 1) * 0.5
under2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.02275)))
over2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.97725)))
tail(data)
                           
174             }          
175             rm(tmp_env)
176         }              
177     }                  
178     invisible(names)   
179 }                      
g <- ggplot(NULL) +
  geom_line(data = data1, aes(x = date, y = close, colour = ticker)) +
  geom_point(data = subset(zandaka, ticker == tarTicker), aes(x = date, y = tanka, colour = ticker)) +
  geom_hline(yintercept = max_drawdown, linetype = "dashed", colour = "blue") +
  annotate("text", label = "max_drawdown", x = min(data1$date), y = max_drawdown + 10, 
           colour = "blue") + 
  geom_hline(yintercept = under2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "-2σ", x = min(data1$date), y = under2sigma - 20,
           colour = "blue") + 
  geom_hline(yintercept = over2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "+2σ", x = min(data1$date), y = over2sigma + 20,
           colour = "blue") + 
  annotate("text", label = round(tail(data1$close, 1) / zandaka[zandaka$ticker == tarTicker, 2] - 1,
                                 digits = 3),
           x = max(data1$date) + 5, y = tail(data1$close, 1) + 30, colour = "blue")

ggplotly(g)

2.2 2559

tarTicker <- c("2559")
data1 <- daily1 %>%
  filter(ticker == tarTicker) %>%
  tail(., 300) %>%
  mutate(return = close / dplyr::lag(close) - 1)
max_drawdown <- tail(data1$close, 1) * 0.5
under2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.02275)))
over2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.97725)))
tail(data)
                           
174             }          
175             rm(tmp_env)
176         }              
177     }                  
178     invisible(names)   
179 }                      
g <- ggplot(NULL) +
  geom_line(data = data1, aes(x = date, y = close, colour = ticker)) +
  geom_point(data = subset(zandaka, ticker == tarTicker), aes(x = date, y = tanka, colour = ticker)) +
  geom_hline(yintercept = max_drawdown, linetype = "dashed", colour = "blue") +
  annotate("text", label = "max_drawdown", x = min(data1$date), y = max_drawdown + 10, 
           colour = "blue") + 
  geom_hline(yintercept = under2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "-2σ", x = min(data1$date), y = under2sigma - 20,
           colour = "blue") + 
  geom_hline(yintercept = over2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "+2σ", x = min(data1$date), y = over2sigma + 20,
           colour = "blue") + 
  annotate("text", label = round(tail(data1$close, 1) / zandaka[zandaka$ticker == tarTicker, 2] - 1,
                                 digits = 3),
           x = max(data1$date) + 5, y = tail(data1$close, 1) + 30, colour = "blue")

ggplotly(g)

2.3 TMF

tarTicker <- c("TMF")
data1 <- daily1 %>%
  filter(ticker == tarTicker) %>%
  tail(., 300) %>%
  mutate(return = close / dplyr::lag(close) - 1)
max_drawdown <- tail(data1$close, 1) * 0.5
under2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.02275)))
over2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.97725)))
tail(data)
                           
174             }          
175             rm(tmp_env)
176         }              
177     }                  
178     invisible(names)   
179 }                      
g <- ggplot(NULL) +
  geom_line(data = data1, aes(x = date, y = close, colour = ticker)) +
  geom_point(data = subset(zandaka, ticker == tarTicker), aes(x = date, y = tanka, colour = ticker)) +
  geom_hline(yintercept = max_drawdown, linetype = "dashed", colour = "blue") +
  annotate("text", label = "max_drawdown", x = min(data1$date), y = max_drawdown + 10, 
           colour = "blue") + 
  geom_hline(yintercept = under2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "-2σ", x = min(data1$date), y = under2sigma - 20,
           colour = "blue") + 
  geom_hline(yintercept = over2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "+2σ", x = min(data1$date), y = over2sigma + 20,
           colour = "blue") + 
  annotate("text", label = round(tail(data1$close, 1) / zandaka[zandaka$ticker == tarTicker, 2] - 1,
                                 digits = 3),
           x = max(data1$date) + 5, y = tail(data1$close, 1) + 30, colour = "blue")

ggplotly(g)

2.4 bitcoin

tarTicker <- c("bitcoin")
data1 <- daily1 %>%
  filter(ticker == tarTicker) %>%
  tail(., 300) %>%
  mutate(return = close / dplyr::lag(close) - 1)
max_drawdown <- tail(data1$close, 1) * 0.5
under2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.02275)))
over2sigma <- tail(data1$close, 1) * (1 + quantile( na.omit(data1$return), c(0.97725)))
tail(data)
                           
174             }          
175             rm(tmp_env)
176         }              
177     }                  
178     invisible(names)   
179 }                      
g <- ggplot(NULL) +
  geom_line(data = data1, aes(x = date, y = close, colour = ticker)) +
  geom_point(data = subset(zandaka, ticker == tarTicker), aes(x = date, y = tanka, colour = ticker)) +
  geom_hline(yintercept = max_drawdown, linetype = "dashed", colour = "blue") +
  annotate("text", label = "max_drawdown", x = min(data1$date), y = max_drawdown + 10, 
           colour = "blue") + 
  geom_hline(yintercept = under2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "-2σ", x = min(data1$date), y = under2sigma - 20,
           colour = "blue") + 
  geom_hline(yintercept = over2sigma, linetype = "dashed", colour = "blue") +
  annotate("text", label = "+2σ", x = min(data1$date), y = over2sigma + 20,
           colour = "blue") + 
  annotate("text", label = round(tail(data1$close, 1) / zandaka[zandaka$ticker == tarTicker, 2] - 1,
                                 digits = 3),
           x = max(data1$date) + 5, y = tail(data1$close, 1) + 30, colour = "blue")

ggplotly(g)